package com.example.aircraftticketingsystemserver.controller;

import com.example.aircraftticketingsystemserver.entity.Passenger;
import com.example.aircraftticketingsystemserver.service.IPassengerService;
import com.example.aircraftticketingsystemserver.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lxz
 * @since 2024-08-19
 */
@RestController
@CrossOrigin(origins = {"*","null"})
@RequestMapping("/passenger")
public class PassengerController {
    @Resource
    private IPassengerService passengerService;
    /**
     * 添加乘客
     */
    @PostMapping("/addPassenger")
    public Result addPassenger(@RequestBody Passenger passenger){
        passengerService.addPassenger(passenger);
        return Result.ok();
    }
    /**
     * 添加用户 乘客联系
     */
    @PostMapping("/addPassengerAndLinkUser")
    public Result addPassengerAndLinkUser( @RequestBody Passenger passenger,
                                           @RequestParam Integer userId){

        passengerService.addPassengerAndLinkUser(passenger, userId);
        return Result.ok();
    }
    /**
     * 删除单个乘客
     */
    @GetMapping("/deletePassenger")
    public Result deletePassenger(Integer passengerId){
        passengerService.deletePassengerById(passengerId);
        return Result.ok();
    }
    /**
     * 批量删除乘客
     */
    @PostMapping("/batchDeletePassenger")
    public Result batchDeletePassenger(@RequestBody List<Integer> passengerIds){
        passengerService.batchDeletePassenger(passengerIds);
        return Result.ok();
    }
    /**
     * 更新乘客
     */
    @PostMapping("updatePassenger")
    public Result updatePassenger(@RequestBody Passenger passenger)
    {
        passengerService.updatePassenger(passenger);
        return Result.ok();
    }

}
